<%--
  Created by IntelliJ IDEA.
  Dept: Gao
  Date: 2021/6/9
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="header.jsp"%>
<html>
<head>
    <title>Title</title>
</head>
<body>

    <form id="formId" class="layui-form  layui-form-pane" >
        <div class="layui-form-item">
            <label class="layui-form-label">输入部门名字</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="title" autocomplete="off"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <input  class="layui-btn"  type="button" onclick="submitForm()" value="添加"/>
        </div>
    </form>


    <script>
        function submitForm() {
            $.post(
                '${path}/dept/insert',
                $('#formId').serialize(), // 封装form表单里面的数据 name=zhangsan
                function(jsonResult) {
                    if (jsonResult.ok){
                        // layer.msg(jsonResult.msg);

                        //当你在iframe页面关闭自身时获得当前弹出框的index索引
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg(
                            jsonResult.msg,
                            {icon : 1, time : 2000},
                            function() {// msg消失之后触发的函数
                                // 关闭弹出层
                                parent.layer.close(index);
                                // 刷新父页面
                                window.parent.location.reload();
                            }
                        );
                    }
                }

            );
        }

    </script>

</body>
</html>
